package bat.ke.qq.com.proxy;

import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class ProxyTest {

    public static void main(String[] args) {

//        UserService userService = new UserServiceImpl();
//        userService.login();
//
//        System.out.println("=======静态代理======");
//        UserServiceProxy userServiceProxy = new UserServiceProxy(userService);
//        userServiceProxy.login();
//
//        System.out.println("=======jdk动态代理======");
//        /**
//         * ClassLoader loader:指定当前目标对象使用的类加载器
//         * Class<?>[] interfaces:指定目标对象实现的接口的类型
//         * InvocationHandler:指定调用处理程序，执行目标对象的方法时,会触发invoke方法
//         */
//        UserService proxyUserService = (UserService) Proxy.newProxyInstance(
//                UserService.class.getClassLoader(), new
//                Class[]{UserService.class}, new DynamicProxyHandler(userService));
//        proxyUserService.login();


        System.out.println("=======cglib动态代理======");
        UserService userServiceImpl = new UserServiceImpl();
        CglibProxy cglibProxy = new CglibProxy(userServiceImpl);
        UserService proxy = (UserService) cglibProxy.getProxyInstance();
        proxy.login();

    }
}